for (election2use in c("2012-GE", "2014-GE", "2016-GE", "2018-GE")) {

  start_date = election_dates[[election2use]] + as.difftime(-31, unit = "days")
  end_date = election_dates[[election2use]] + as.difftime(0, unit = "days")
  
  seq2use <- data.frame(seq(from = start_date, to = end_date, by = 1))
  names(seq2use) <- "received_date"
  
  ## D-R plot
  abl2use <- abl_files[[election2use]] %>%
    filter(received_type == "MA",
           !is.na(received_date),
           received_date <= end_date,
           received_date >= start_date) %>%
    count(received_date, enrollment) %>%
    spread(enrollment, n, fill = 0) %>%
    left_join(x = seq2use, y = .) %>%
    replace(is.na(.), 0)
  
  abl2use$days_before <- seq(from = 31, to = 0, by = -1)

  p <- abl2use %>%
    ggplot(aes(y = D - R, x = received_date, size = D + R, weight = D + R,  shape = wday(received_date) %in% c(1,7))) +
    scale_shape_manual(guide = FALSE, values = c(21, 19)) +
    geom_point() +
    geom_smooth(se = FALSE, color = "gray") +
    scale_size_continuous(guide = FALSE) +
    scale_y_continuous(limits = c(-500, 1500)) +
    xlab("Date") +
    ylab("Democratic - Republican difference")
    
  filename2use <- paste("~/research/vbm-vulnerable-maine/plots/maine-d-r-differences-", election2use, ".pdf", sep = "")
  ggsave(p, filename = filename2use, width = 6, height = 6)
  
  ## D-everyone else plot
  abl2use <- abl_files[[election2use]] %>%
    filter(received_type == "MA",
           !is.na(received_date),
           received_date <= end_date,
           received_date >= start_date) %>%
    count(received_date, enrollment) %>%
    spread(enrollment, n, fill = 0) %>%
    left_join(x = seq2use, y = .) %>%
    replace(is.na(.), 0) 

  abl2use$notD <- rowSums(abl2use[,sapply(abl2use, is.numeric)]) - abl2use$D

  abl2use$days_before <- seq(from = 31, to = 0, by = -1)
  
  p <- abl2use %>%
    ggplot(aes(y = D - notD, x = received_date, size = D + notD, weight = D + notD,  shape = wday(received_date) %in% c(1,7))) +
    scale_shape_manual(guide = FALSE, values = c(21, 19)) +
    geom_point() +
    geom_smooth(se = FALSE, color = "gray") +
    scale_size_continuous(guide = FALSE) +
    scale_y_continuous(limits = c(-1500, 1500)) +
    xlab("Date") +
    ylab("Democratic - not Democratic difference")
  
  filename2use <- paste("~/research/vbm-vulnerable-maine/plots/maine-d-not-d-differences-", election2use, ".pdf", sep = "")
  ggsave(p, filename = filename2use, width = 6, height = 6)
  
  ## Receipts by day
  
  abl2use <- abl_files[[election2use]] %>%
    filter(received_type == "MA",
           !is.na(received_date),
           received_date <= end_date,
           received_date >= start_date) %>%
    group_by(received_date) %>%
    summarize(ballots = n()) %>%
    left_join(x = seq2use, y = .) %>%
    replace(is.na(.), 0)
  
 p <- abl2use %>%
    ggplot(aes(y = ballots / 1000, x = received_date, shape = wday(received_date) %in% c(1,7))) +
    scale_shape_manual(guide = FALSE, values = c(21, 19)) +
    geom_point(size = 2) +
    scale_size_continuous(guide = FALSE) +
    scale_y_continuous(limits = c(0, 8)) +
    xlab("Date") +
    ylab("Received VBM ballots") +
    geom_smooth(se = FALSE, color = "gray")
    
  filename2use <- paste("~/research/vbm-vulnerable-maine/plots/maine-total-VBM-receipts-", election2use, ".pdf", sep = "")
  ggsave(p, filename = filename2use, width = 3, height = 3)
  
}

